package com.lyy.king.tools.service.file.handler.excel;

import com.lyy.king.common.utils.utils.LoggerUtils;
import com.lyy.king.tools.enums.ImportExcelOperatorTypeEnum;
import com.lyy.king.tools.model.dto.importExcel.BaseImportExcelOperatorDTO;

import org.slf4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: cdx
 * @Created: 2023/12/26 19:46
 */
@Service
public abstract class ImportExcelOperatorEngine<IMPORT_EXCEL_DTO extends BaseImportExcelOperatorDTO> extends ImportExcelOperatorEngineFactory implements InitializingBean {

    protected static Logger logger = LoggerUtils.getLogger(ImportExcelOperatorEngine.class);


    /**
     * 执行处理
     *
     * @param fileDownUrl
     * @return
     */
    public boolean execute(String fileDownUrl) {
        try {

            // 根据下载链接获取 excel文件
            // 构造数据
            // 导入数据
        } catch (Exception e) {
            LoggerUtils.error(logger, "import excel operator error:[{}],operatorType:[{}]"
                    , e.getMessage(),getOperatorType().getDesc());
        }
        return true;
    }




    /**
     * 获取当前操作类型
     *
     * @return
     */
    protected abstract ImportExcelOperatorTypeEnum getOperatorType();

    /**
     * excel对应的数据类
     *
     * @throws Exception
     */
    protected abstract Class<IMPORT_EXCEL_DTO> getDateTypeClass();

    /**
     * 导入数据
     *
     * @param data
     */
    protected abstract void importData(List<IMPORT_EXCEL_DTO> data);


    @Override
    public void afterPropertiesSet() throws Exception {
        // 注册处理器
        importExcelOperatorEngineMap.put(getOperatorType(), this);
    }
}
